#!/usr/bin/python3
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: t -*-

import os
import abc
from _const import Const


class PluginManager:

    def __init__(self, param):
        self.param = param

    def getPluginList(self):
        ret = []
        for fn in os.listdir(os.path.join(Const.libDir, "plugins")):
            exec("from plugins import %s" % (fn))
            plugin = eval("%s.Plugin()" % (fn))
            ret.append(plugin)
        return ret

    def getPlugin(self, os_name):
        for fn in os.listdir(os.path.join(self.param.libDir, "plugins")):
            exec("from plugins import %s" % (fn))
            plugin = eval("%s.Plugin()" % (fn))
            if os_name in plugin.get_os_name_list():
                return plugin
        return None


class PluginBase(abc.ABC):

    @abc.abstractmethod
    def get_os_name_list(self):
        pass

    @abc.abstractmethod
    def get_os_icon(self, os_name):
        pass

    @abc.abstractmethod
    def get_vm_constraint(self, os_name, build_or_run):
        pass

    @abc.abstractmethod
    def is_hardware_supported(self, os_name):
        pass

    @abc.abstractmethod
    def create_setup_iso_async(self, os_name, tmp_dir, progress_callback):
        pass

    @abc.abstractmethod
    def create_setup_iso_cancel(self):
        pass

    @abc.abstractmethod
    def create_setup_iso_finish(self):
        pass

    @abc.abstractmethod
    def update_vm_config(self, os_name, vm_config):
        pass
